package com.vise.facedemo.alioss.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.vise.facedemo.R;
import com.vise.facedemo.alioss.http.API;
import com.vise.facedemo.bean.JX;

import java.text.NumberFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * 分类
 */
public class One_Fragment extends Fragment {
    View view;

    Unbinder unbinder;
//    @BindView(R.id.textView4)
//    TextView textView4;
    @BindView(R.id.tv_shenbaitai)
    TextView tvShenbaitai;
    @BindView(R.id.tv_botai)
    TextView tvBotai;
    @BindView(R.id.tv_youchihen)
    TextView tvYouchihen;
    @BindView(R.id.tv_youdianci)
    TextView tvYoudianci;
    @BindView(R.id.tv_wuliewen)
    TextView tvWuliewen;
    @BindView(R.id.tv_nitai)
    TextView tvNitai;
    @BindView(R.id.tv_shexingzhengchang)
    TextView tvShexingzhengchang;
    @BindView(R.id.tv_zaotai)
    TextView tvZaotai;
    @BindView(R.id.tv_danhongshe)
    TextView tvDanhongshe;
    @BindView(R.id.tv_shitaibubo)
    TextView tvShitaibubo;
    @BindView(R.id.tv_changjianbiaoxian)
    TextView tvChangjianbiaoxian;
    @BindView(R.id.tv_fabingqingxiang)
    TextView tvFabingqingxiang;
    @BindView(R.id.tv_yongyaojinji)
    TextView tvYongyaojinji;
    @BindView(R.id.tv_yaowuyangsheng)
    TextView tvYaowuyangsheng;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = View.inflate(getActivity(), R.layout.fragment_f1, null);
            ButterKnife.bind(this, view);
            initview();
            initview2();
        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }


        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    private void initview() {
        String Changjianbiaoxian = API.tiaoli.getChangjianbiaoxian();
        String Fabingqingxiang = API.tiaoli.getFabingqingxiang();
        String Yongyaijinji = API.tiaoli.getYongyaijinji();
        String Yaowuyangsheng = API.tiaoli.getYaowuyangsheng();

        tvChangjianbiaoxian.setText(Changjianbiaoxian);
        tvFabingqingxiang.setText(Fabingqingxiang);
        tvYongyaojinji.setText(Yongyaijinji);
        tvYaowuyangsheng.setText(Yaowuyangsheng);

    }

    void initview2() {
        List<JX.CharBean> charBeans = API.charX;
        for (int i = 0; i < charBeans.size(); i++) {
            String probability = charBeans.get(i).getProbability();
            NumberFormat num = NumberFormat.getPercentInstance();
            num.setMaximumIntegerDigits(3);
            num.setMaximumFractionDigits(2);
            double csdn = Double.parseDouble(probability);
            String format = num.format(csdn);
            Log.e("zzz", "xx"+format);
            switch (charBeans.get(i).getType()) {
                case "深白苔":
                    tvShenbaitai.setText(format);

                    break;
                case "薄苔":
                    tvBotai.setText(format);

                    break;
                case "有齿痕":
                    tvYouchihen.setText(format);
                    break;
                case "有点刺":
                    tvYoudianci.setText(format);

                    break;
                case "无裂纹":
                    tvWuliewen.setText(format);

                    break;
                case "腻苔":
                    tvNitai.setText(format);

                    break;
                case "舌形正常":
                    tvShexingzhengchang.setText(format);

                    break;
                case "淡红舌":
                    tvDanhongshe.setText(format);
                    break;
                case "舌苔不剥":
                    tvShitaibubo.setText(format);

                    break;
                default:
                    break;
            }

        }

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
